package net.qiyuesuo.utils;

import net.qiyuesuo.utils.file.PropertiesUtils;

/**
 * 根据不同数据库 判断 执行的sql
 * @author Administrator
 *
 */
public class SqlUtils {
	
	private static String database = PropertiesUtils.getDataBaseProperty("database");

	/**
	 * 根据 uuid获取记录 sql
	 * @param fileKey
	 * @return sql语句
	 */
	public static String getInfoSql(String fileKey) {
		String sql = null;
		switch (database) {
		case "oracle":
			sql = "select * from \"SYSTEM\".\"FileMeta\" where \"fileKey\" = '" + fileKey + "'";
			break;
		default:
			sql = "select * from FileMeta where fileKey = '" + fileKey + "'";
			break;
		}
		return sql;
	}
	
	/**
	 * 根据uuid 获取 删除记录  sql
	 * @param fileKey
	 * @return sql语句
	 */
	public static String getDeleteSql(String fileKey) {
		String sql = null;
		switch (database) {
		case "oracle":
			sql = "delete from \"SYSTEM\".\"FileMeta\" where \"fileKey\" = '"+fileKey+"'";
			break;
		default:
			sql = "delete from FileMeta where fileKey ='"+fileKey+"'";
			break;
		}
		return sql;
	}
	
	/**
	 * 获取 插入记录 sql 
	 * @return sql语句
	 */
	public static String getInsertSql() {
		String sql = null;
		switch (database) {
		case "oracle":
			sql = "insert into \"SYSTEM\".\"FileMeta\" (\"fileKey\",\"size\",\"createTime\") values(?,?,?)";
			break;
		default:
			sql = "insert into FileMeta (fileKey,size,createTime) values(?,?,?)";
			break;
		}
		return sql;
	}
	
	/**
	 * 获取 更新记录 sql
	 * @return sql语句
	 */
	public static String getUpdateSql() {
		String sql =null;
		switch (database) {
		case "oracle":
			sql = "update \"SYSTEM\".\"FileMeta\" set \"size\" = ?,\"createTime\" = ? where \"fileKey\" = ?";
			break;
		default:
			sql = "update FileMeta set size = ? ,createTime = ? where fileKey = ?";
			break;
		}
		return sql;
	}
	
}

